import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import jotaiDebugLabel from 'jotai/babel/plugin-debug-label'
import jotaiReactRefresh from 'jotai/babel/plugin-react-refresh'
import svgr from 'vite-plugin-svgr'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import removeConsole from "vite-plugin-remove-console";

// https://vitejs.dev/config/
export default defineConfig(() => {
    return {
        plugins: [
          react({
              babel: {
                  parserOpts: {
                      plugins: ['decorators-legacy', 'classProperties']
                  },
                  plugins: [jotaiDebugLabel, jotaiReactRefresh]
              }
          }), removeConsole(),
          svgr({
              exportAsDefault: true,
              svgrOptions: {
                  svgProps: {
                      className: 'icon'
                  },
                  prettier: false,
                  dimensions: false
              }
          }),
          monacoEditorPlugin.default({}),
      ],
        //配置跨域的地方
        server:{
          port: 5173,//端口号
          host:true,
          open:false,//是否自动启动
          proxy:
              {
                  "/api":
                      {
                          target: 'http://127.0.0.1:8080',
                          changeOrigin:
                              true, //是否跨域
                          rewrite:
                              (p) => p.replace(/^\/api/, ''), //重写路径
                      }
                  ,
              }
          ,
      },
        preview:{
      https: true,
    },
        resolve: {
          alias: {
              "@":
                  path.resolve(__dirname, './src')//配置@别名
          }
        },
        base: '/',
        build: {
            minify: true,// 开启压缩
            rollupOptions: {
                treeshake: true, // 开启 Tree Shaking，消除未使用的代码，减小最终的包大小
            }
        }
    }
})
